<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="/WEB-INF/myTag.tld" prefix="page" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${rootPath}/css/common.css" type="text/css" rel="stylesheet" />
<title>云商宝终端序列号查询</title>

<script type="text/javascript"
	src="<s:url value="/js/jquery-1.3.2.js" />"></script>
<script type="text/javascript" src="<s:url value="/js/common.js" />"></script>
<script language="javascript" type="text/javascript"
	src="<s:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
<script type='text/javascript' src='<s:url value="/dwr/engine.js"/>'></script>
<script type='text/javascript' src='<s:url value="/dwr/interface/MccQuery.js"/>'></script>	
<script type="text/javascript">
$(document).ready(function() {
loadYsbBrandCode();
var init=0;
$("#confirmBtn").click(
		function(){
			var dd = $("input[name=multi_sel]:checked");
			if(dd.length != 1){
				alert("请选择一条记录");
				return false;
			}
			var idd = dd.val();							
			if(dd.length == 0){
				alert("请选择记录");
				return false;
			}else{				
				var str= idd.substr(0,2);
    			if(str=='YJ')
    			{
    				var isBind=confirm("选中的序列号不是有效的!确定继续绑定?");
    				if(!isBind)
        			{
        				return;
        			}
    			}
    			var arr = idd.split("_");
				if(init>0){
					alert("请勿重复提交");
					return;
				}
				init=init+1;
				//防止多次点击绑定
				$("#sub").attr("disabled",true);
				$("#confirmBtn").attr("disabled","disabled");
                 $.ajax({
                	 url:'ysbTermSnRepAgentSelect.ct',
                	 type:'post',
                	 data:'tid='+$("#tid").val()+'&mid='+$("#mid").val()+'&serialNumer='+arr[0]+"&posBrandCode="+arr[1]+"&posModelNo="+arr[2] ,
                	 dataType:'json',
                	 success:function(data)
                	 {
                		 var invaild=data.invaild;
                		 if(invaild=="error")
                		{
                			 alert("参数异常,请刷新页面或者重新登录!!!");
                			 window.close();
                		}
                		 else{
                			 var msg = data.message;
                			 alert(msg);
                             window.opener.document.getElementById("queryUserForm").submit();
                    		 window.close();
                		 }
                	 },
                	 error:function(data)
                	 {
                		 alert("换机失败");
                		 window.close();
                	 }
                 })          				
			}
		});
		
		$("#sub").click(function(){
			$(this).attr("disabled",true);
			var tid=$("#tid").val();
			var mid=$("#mid").val();
			var agentId=$("#agentId").val();
			$("#importForm").attr("action","<%=basePath %>ysbTermSnRepAgent/ysbTermSnRepAgentList.ct?tid="+tid+"&mid="+mid+"&agentId="+agentId);
			$("#importForm").submit();
		
		});
  });
  
  
  //加载终端名称
	function loadYsbBrandCode() {
	  
			var sortCode = $("#posBrand").val();
			if (sortCode==null||sortCode==""||sortCode=="-1") {
				$("#posName").empty().append("<option value='-1'>不限</option>");
				return;
			}
			
			MccQuery.loadYsbBrandNameByCode(sortCode, function(sortSmall) {
				fillSelect_sort("posName", sortSmall,sortCode);
			});
		}
			
	
	function fillSelect_sort(sid, address,sortCode) {
	  	
				if (!address || !sid) {
					return;
				}
				
				var $select = $("#" + sid);
				$select.empty();
				
				$("#" + sid).empty().append("<option value='-1'>不限</option>");
		        var selModelCode = $("#selModelCode").val();
		        var oldBandCode = $("#oldBandCode").val();
				
				for ( var i = 0; i < address.length; i++) {
			        var selStr = "";
					if(selModelCode != null && selModelCode != '' && address[i].CODE == selModelCode 
							&& sortCode == oldBandCode){
						selStr = " selected='selected' ";
					}
					$select.append("<option " + selStr + " value='"+address[i].CODE+"'>"
							+ address[i].NAME + "</option>");
				}
/* 
				if(choiseId!="" && choiseId!=null){
				 $("#" + sid).val(choiseId);
				} */
		}		
  
  
</script>
</head>
<body>
	<div class="subpage">
		<s:form id="importForm" action="ysbTermSnRepAgentList.ct" method="post"
			namespace="/ysbTermSnRepAgent"  theme="simple">
			<input id="tid" name="searchCondition.tid" value="<s:property value="searchCondition.tid"/>" type="hidden"/>
			<input id="mid" name="searchCondition.mid" value="<s:property value="searchCondition.mid"/>" type="hidden"/>
			<input id="agentId" name="searchCondition.agentId" value="<s:property value="searchCondition.agentId"/>" type="hidden"/>
			<table class="tb">
   			 <tbody>
        		<tr class="tb-line">
            		<td class="tb-td" colspan="8"><div class="tb-h2">POS收单运营管理平台</div></td>
        		</tr>
				<tr class="tb-line">
					<td class="tb-td" colspan="8">
						<div class="tb-h3">
							云商宝终端序列号查询
						</div>
					</td>
				</tr>
				<tr class="tb-line">
					   <td width="12%" style="min-width: 100px" align="right" class="tb-td"><div class="tb-h4">品牌：</div></td>
						<td class="tb-td"><label class="tb-select">
							<s:select cssClass="queryWidth" name="searchCondition.posBrand"
								id="posBrand" onchange="loadYsbBrandCode()"
								list="#request.brandMap" listKey="key" listValue="value"  headerKey="-1" headerValue="不限"/>
								</label>
						</td>
						<td width="12%" style="min-width: 100px" align="right" class="tb-td"><div class="tb-h4">型号：</div></td>
						<td class="tb-td"><label class="tb-select">
							<s:select cssClass="queryWidth" name="searchCondition.posName"
								id="posName"
								list="#request.nameMap" listKey="key" listValue="value"/>
								</label>
								<s:hidden id="selModelCode" name="#request.selModelCode"  />
								<s:hidden id="oldBandCode" name="#request.oldBandCode"  />
						</td>
						<td width="12%" style="min-width: 100px" align="right" class="tb-td"><div class="tb-h4">类型：</div></td>
						<td class="tb-td"><label class="tb-select">
							<s:select cssClass="queryWidth" name="searchCondition.posType"
								id="orgCode"
								list="#request.typeMap" listKey="key" listValue="value"   headerKey="-1" headerValue="不限"/>
								</label>
						</td>
							<td width="12%" style="min-width: 100px" align="right" class="tb-td"><div class="tb-h4">pos序列号：</div></td>
							
							<td class="tb-td"><label class="tb-input-normal"><s:textfield id="serialNum"
							name="searchCondition.serialNum" cssClass="queryWidth" />
								</label>
						</td>
						</tr>
						

				<tr>
					<td colspan="8">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="8" align="center"><div style="color: blue;">
							<s:actionmessage />
						</div>
						<div style="color: red;">
							<s:actionerror />
						</div></td>
				</tr>

				<tr class="tb-line">
					<td class="tb-td line-submit" colspan="8" align="center">
					<label class="tb-input-submit"><s:submit value="查询" id="sub" /></label> 
					<label class="tb-input-submit"><input type="button" id='confirmBtn' value='确定'/></label></td>
				</tr>
				<s:if
					test="#request.searchRsList != null && #request.searchRsList.size>0">
					<tr class="tb-line">
						<td class="tb-td paging" colspan="8"><page:pageCount
								max_pages="11" totalPage="${requestScope.totalPage}"
								currentPage="${requestScope.currentPage}"
								action="${rootPath}/ysbTermSnRepAgent/ysbTermSnRepAgentList.ct?searchCondition.tid=00000001&searchCondition.mid=952710215827635&searchCondition.agentId=1430&currentPage=" />
						</td>
					</tr>
				</s:if>
			</table>
			
			<div class="big-tb">
            <table class="tb" style="width: 100%;">
				<thead>
            	<tr class="tb-line">
					<th class="tb-th" colspan="6"><div class="tb-h3">终端信息列表</div></th>
				</tr>
					<tr class="tb-line bg-gray">
					    <th class="tb-th">选择</th>
					    <th class="tb-th">终端序列号</th>
						<th class="tb-th">品牌</th>
						<th class="tb-th">型号</th>
						<th class="tb-th">类型</th>
						<!--<th>机构</th>-->
						<th class="tb-th">是否已出库</th>
					</tr>
				</thead>
				<tbody>
					<s:iterator value="#request.searchRsList" status="stat" id="term">
							<tr class="tb-line">
                            <td class="tb-td" align="center">
                             <s:checkboxlist name="multi_sel" list="#{#term.serialNum+'_'+#term.posBrandCode+'_'+#term.posBrandName:''}"  theme="simple"/>
                            </td>                            
							<td class="tb-td">
							 <s:property value="#term.serialNum"/>
							</td>
							<td class="tb-td">
							 <s:property value="#term.posBrand"/>
							</td>
							<td class="tb-td">
							 <s:property value="#term.posName"/>
							</td>
							<td class="tb-td">
							 <s:property value="#term.posType"/>
							</td>
							<!--  
							<td>
							 <s:property value="#term.orgName"/>
							</td>
							-->
							<td class="tb-td">
							 <s:property value="#term.isUsed"/>
							</td>
							</tr>
						</s:iterator>
				</tbody>
			</table>
	</div>
	</s:form>
	</div>
</body>
</html>